#include "handleServer.h"
#include "tcp_server_test.h"
int main(int argc, char *argv[]) {
  // if (daemon(0, 0) < 0) { // TODO: 后台怎么输出文件？
  //   std::cout << "failed daemon" << std::endl;
  // }
  sdx::handleSignal handleSignal;
  handleSignal.sigMainHandle();

  sdx::TcpServer tcpServer;
  tcpServer.createSocket();
  tcpServer.bindIp();
  tcpServer.listenData();
  while (true) {
    tcpServer.acceptMessage();
    while (true) {
      int recv = tcpServer.recvMessage();
      if (recv == 0) {
        std::cout << "did not recv anything" << std::endl;
        break;
      }
      tcpServer.sendMessage();
    }
    tcpServer.closeAccept();
  }
  std::cout << "quit server..." << std::endl;
  tcpServer.closeSocket();
  return 0;
}